# -*- coding:utf-8 -*-
import threading
import time


sem = threading.Semaphore(2)


class DemoThread(threading.Thread):

    def run(self):
        # print('{0} is waiting semaphore.'.format(self.name))
        sem.acquire()
        print('{0} acquired semaphore({1}).'.format(self.name, time.ctime()))
        time.sleep(2)
        # print('{0} release semaphore.'.format(self.name))
        sem.release()


if __name__ == '__main__':
    threads = []
    for i in range(10):
        threads.append(DemoThread(name='Thread-' + str(i)))
    for t in threads:
        t.start()
    for t in threads:
        t.join()